package cn.doourbest.controller;

import cn.doourbest.bean.ApplicationScopeService;
import cn.doourbest.bean.RequestScopeService;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.annotation.RequestScope;

/**
 * b
 *
 * @author zhangsc
 * @date 2020/9/16 19:22
 */
@RestController
@RequestMapping("/a")
@RequestScope
public class MyController implements ApplicationContextAware {

    private ApplicationContext applicationContext;



    @RequestMapping("/b")
    @ResponseBody
    public String getName(){
        ApplicationScopeService bean = applicationContext.getBean(ApplicationScopeService.class);
        RequestScopeService bean1 =  applicationContext.getBean(RequestScopeService.class);
        return bean.getName();
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }
}
